﻿/**
 *       Project: ServerLib
 *     Copyright: Copyright (C) 2008, Rob Kennedy
 *   Create Date: 2008-07-15 3:40 PM
 * Modified Date: 2008-07-15 3:40 PM    RK  Added comments
 *      Comments: Ignore SA1633.
 *      
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace ServerLib.Settings
{
    using System;
    using System.Data;
    using ServerLib.Core;
    using ServerLib.Data;

    /// --------------------------------------------------------------------
    /// Project	 : ServerLib
    /// Class	 : Message
    /// Inherits : DataRowRecord
    /// --------------------------------------------------------------------
    /// <summary>
    /// A class representation of a message database record
    /// </summary>
    /// <authorname>Rob Kennedy</authorname>
    /// <remarks></remarks>
    /// --------------------------------------------------------------------
    public class Message : DataRowRecord
    {
        #region Public Properties

        /// <summary>
        /// Gets the unique Message record Identifier number
        /// </summary>
        public int MessageID
        {
            get
            {
                return Types.FixInteger(this.InternalDataRow["MessageID"]);
            }
        }

        /// <summary>
        /// Gets or sets the unique Message record Identifier string
        /// </summary>
        public int UniqueID
        {
            get
            {
                return Types.FixInteger(this.InternalDataRow["UniqueID"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["UniqueID"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Folder ID of the owner folder
        /// </summary>
        public int FolderID
        {
            get
            {
                return Types.FixInteger(this.InternalDataRow["FolderID"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["FolderID"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the unique user id for the message owner
        /// </summary>
        public int UserID
        {
            get
            {
                return Types.FixInteger(this.InternalDataRow["UserID"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["UserID"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the From name value
        /// </summary>
        public string FromName
        {
            get
            {
                return Types.FixString(this.InternalDataRow["FromName"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["FromName"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the From address value
        /// </summary>
        public string FromAddress
        {
            get
            {
                return Types.FixString(this.InternalDataRow["FromAddress"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["FromAddress"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Reply name value
        /// </summary>
        public string ReplyName
        {
            get
            {
                return Types.FixString(this.InternalDataRow["ReplyName"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["ReplyName"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Reply address value
        /// </summary>
        public string ReplyAddress
        {
            get
            {
                return Types.FixString(this.InternalDataRow["ReplyAddress"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["ReplyAddress"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Message Subject value
        /// </summary>
        public string Subject
        {
            get
            {
                return Types.FixString(this.InternalDataRow["Subject"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["Subject"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Message Date value
        /// </summary>
        public DateTime Date
        {
            get
            {
                return Types.FixDateTime(this.InternalDataRow["DateTime"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["DateTime"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this message is spam
        /// </summary>
        public bool IsSpam
        {
            get
            {
                return Types.FixBoolean(this.InternalDataRow["IsSpam"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["IsSpam"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this message is read
        /// </summary>
        public bool IsRead
        {
            get
            {
                return Types.FixBoolean(this.InternalDataRow["IsRead"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["IsRead"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Message data file path value
        /// </summary>
        public string MessagePath
        {
            get
            {
                return Types.FixString(this.InternalDataRow["MessagePath"]);
            }

            set
            {
                if (this.InternalDataRow.RowState == System.Data.DataRowState.Unchanged)
                {
                    this.InternalDataRow.BeginEdit();
                }

                this.InternalDataRow["MessagePath"] = value;
            }
        }

        #endregion

        #region Public Constructors

        /// <summary>
        /// Initializes the Message object with a new DataRow class
        /// </summary>
        /// <param name="dataConnection">The IDatabase object to connect with</param>
        public Message(IDatabase dataConnection)
            : base(dataConnection)
        {
        }

        /// <summary>
        /// Initializes the Message object with a new DataRow class
        /// </summary>
        /// <param name="dataConnection">The IDatabase object to connect with</param>
        /// <param name="tableName">The Record table name to load into the Record object</param>
        /// <param name="fieldName">The Record table field name name used to identify when loading the recordId</param>
        /// <param name="recordId">The unique record ID number to load into the Record object</param>
        public Message(IDatabase dataConnection, string tableName, string fieldName, int recordId)
            : base(dataConnection, tableName, fieldName, recordId)
        {
        }

        /// <summary>
        /// Initializes the Message object with a new DataRow class
        /// </summary>
        /// <param name="dataTable">The DataTable object to retrieve a new DataRow object from</param>
        public Message(DataTable dataTable)
            : base(dataTable)
        {
        }
        
        /// <summary>
        /// Initializes the Message object with a new DataRow class
        /// </summary>
        /// <param name="dataRow">The DataRow object to initialize the Domain object with</param>
        public Message(DataRow dataRow)
            : base(dataRow)
        {
        }
        #endregion
    }
}
